package com.rky.spring.cloud.factory;

import com.rky.spring.cloud.api.EmployeeRemoteService;
import com.rky.spring.cloud.entity.Employee;
import com.rky.spring.cloud.util.ResultEntity;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 0x_Jss
 * @date 2022年02月19日 16:54
 * @description 实现Consumer端服务降级功能
 */
@Component //将当前类的对象加入IOC容器

public class MyFallBackFactory implements FallbackFactory<EmployeeRemoteService> {

    @Override
    public EmployeeRemoteService create(Throwable cause) {
        return new EmployeeRemoteService() {
            @Override
            public Employee getEmployeeRemote() {
                return null;
            }

            @Override
            public List<Employee> getEmpListRemote(String keyword) {
                return null;
            }

            @Override
            public ResultEntity<Employee> getEmpWithCircuitBreaker(String signal) {
                return ResultEntity.failed("降级机制生效：" + cause.getMessage());
            }
        };
    }
}